#!/usr/bin/env bash
#########################################################################
# File Name   : nova.sh.j2
# Author      : seadog
# mail        : seadog0514@163.com
# Version     : 0.1
# Created Time: Mon 2024-09-30 13:17:38(+0800)
#########################################################################

#
#
# Usage:

{
  set -euo pipefail
  # set -E
  #     If set, any trap on ERR is inherited by shell functions, command
  #     substitutions, and commands executed in a subshell environment.

}

source /root/keystonerc

# create [nova] user in [service] project
openstack --insecure user create --domain default --project service --password {{ service_password }} nova

# add [nova] user in [admin] role
openstack --insecure role add --project service --user nova admin
# create [placement] user in [service] project
openstack --insecure user create --domain default --project service --password {{ service_password }} placement

# add [placement] user in [admin] role
openstack --insecure role add --project service --user placement admin
# create service entry for [nova]
openstack --insecure service create --name nova --description "OpenStack Compute service" compute

# create service entry for [placement]
openstack --insecure service create --name placement --description "OpenStack Compute Placement service" placement

# define Nova API Host
export controller={{ inventory_hostname }}
# create endpoint for [nova] (public)
openstack --insecure endpoint create --region RegionOne compute public https://$controller:8774/v2.1/%\(tenant_id\)s

# create endpoint for [nova] (internal)
openstack --insecure endpoint create --region RegionOne compute internal https://$controller:8774/v2.1/%\(tenant_id\)s

# create endpoint for [nova] (admin)
openstack --insecure endpoint create --region RegionOne compute admin https://$controller:8774/v2.1/%\(tenant_id\)s

# create endpoint for [placement] (public)
openstack --insecure endpoint create --region RegionOne placement public https://$controller:8778

# create endpoint for [placement] (internal)
openstack --insecure endpoint create --region RegionOne placement internal https://$controller:8778

# create endpoint for [placement] (admin)
openstack --insecure endpoint create --region RegionOne placement admin https://$controller:8778
